﻿// Notepad+
// (C) 2014 Jan Kowalewicz <kowalewicz.jan@live.de>
//
// RunModule.cs
// This file is part of the Notepad+ Project
//
// THIS PROJECT IS PUBLISHED UNDER THE TERMS OF THE LGPLv3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Security.Permissions;

namespace notepadplus
{
    static class RunModule
    {
        // Application entry point
        [STAThread]
        [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
        static void Main()
        {
            Type isMono = Type.GetType("Mono.Runtime");
            if (isMono != null)
                throw new Exception("RuntimeError: current platform 'mono' is not supported.");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainWindow());
            AppDomain tdm = AppDomain.CurrentDomain;
            tdm.UnhandledException += new UnhandledExceptionEventHandler(Handle);
            try
            {
                throw new Exception("UNKNOWN ERROR at notepadplus.RunModule, notepadplus.RunModule.[static void Main()].");
            }
            catch (Exception ex)
            {
                MessageBox.Show("unknown: {0} \n" + ex.Message);
            }
        }
        static void Handle(object sender, UnhandledExceptionEventArgs args)
        {
            Exception ex = (Exception)args.ExceptionObject;
            MessageBox.Show("Handle caught : " + ex.Message);
            MessageBox.Show("Runtime TERMINATING!: {0}" + args.IsTerminating);
        }
    }
}
